package pijunn

import com.pijunn.report.FoundEvent;
import com.pijunn.report.LostEvent;
import com.pijunn.users.AppUser;

class IndexController {
	/**
	 * Dependency injection for the springSecurityService.
	 */
	def springSecurityService

    def index() { 
		AppUser user = springSecurityService?.currentUser
		def foundItems
		def lostItems
		if (user) {
			def c = FoundEvent.createCriteria()
			foundItems = c.list {
				isNull("handlingAmount")
				item { 
					label {
						registeredTo {
							eq("id", user.id)
						}
					}
				}
			}
			lostItems = LostEvent.withCriteria {
				//isNull('foundDate')
				item {
					label {
						registeredTo {
							eq("id", user.id)
						}
					}
				}
			}
		}
		[loggedIn: user, foundItems: foundItems, lostItems: lostItems]
	}
}
